class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int n = s.size();
        int left=0;
        int right = 0;
        int hash[128]={0};
        int mx =0;
        while(right<n)
        {
            //先进入窗口
            hash[s[right]]++;
            //判断是否重复
            while(hash[s[right]]>1)
            {
                //重复就出窗口
                hash[s[left++]]--;
            }
            //更新值
            mx = mx>(right-left+1)?mx:(right-left+1);
            right++;
        }
        return mx;
    }
};